package com.example.cookie02.conterller;

import com.alibaba.fastjson.JSON;
import com.example.cookie02.dao.imp.PersonDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

/**
 * @author ：lqs
 * @date ：Created in 2023/9/2 14:55
 * @description：
 * @modified By：
 * @version:
 */
@WebServlet("/getname")
public class GetNameController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String getname = req.getParameter("getname");
        PersonDaoImpl personDao = new PersonDaoImpl();
        List<Map<String,Object>> mapList= personDao.queryName(getname);
        PrintWriter writer = resp.getWriter();
        int count = mapList.size();
//        需要JSON 的时候 把对象转换为JSON字符串
//        String jsonstr = JSONUtil.toJsonStr(deptById);
//        阿里的 JSON转换工具
        String jsonString = JSON.toJSONString(count);
        writer.println(jsonString);
    }
}

